<?php
	
autoLoader();

// display( $_REQUEST );
// display( $_POST ); exit;

if( false == isset( $_POST['Submit'] ) ) { 
	$str = '';
	$str .= '<form name=myform method=post action=modules.php?file=wards&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
	$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
	echo $str;
	exit;
}

if( true == isset( $_POST['operation'] ) && 'insert' == strtolower( $_POST['operation'] ) ) {
	
	$objBaseWard 	= new BaseWards();
	
	$objBaseWard->setRoomNumber( $_POST['room_number'] );
	$objBaseWard->setWardTypeId( $_POST['ward_type'] );
	$objBaseWard->setRate( $_POST['rate'] );
	$objBaseWard->setIsAvaliable( ( true == valStr( $_POST['is_avaliable'] ) ) ? $_POST['is_avaliable'] : 1 );
	$objBaseWard->setMoveOutDate( ( true == valStr( $_POST['move_out_date'] ) ) ? $_POST['move_out_date'] : 'NULL' );
	$objBaseWard->setReservationId( ( true == valStr( $_POST['reservation_id'] ) ) ? $_POST['reservation_id'] : 'NULL' );
	$objBaseWard->setReportingDoctorId( ( true == valStr( $_POST['reporting_doctor_id'] ) ) ? $_POST['reporting_doctor_id'] : 'NULL' );
	$objBaseWard->setPatientId( ( true == valStr( $_POST['patient_id'] ) ) ? $_POST['patient_id'] : 'NULL' );
	$objBaseWard->setDepartmentId( $_POST['department_id'] );
	$objBaseWard->setFacilities( ( true == valStr( $_POST['facilities'] ) ) ? $_POST['facilities'] : 'NULL' );
	$objBaseWard->setCreatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseWard->setCreatedOn( 'now()' );
	$objBaseWard->setUpdatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseWard->setUpdatedOn( 'now()' );
	
	if( 1 == $objBaseWard->insert() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_wards&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
} else if( true == isset( $_POST['operation'] ) && 'update' == strtolower( $_POST['operation'] ) ) {
	
	$objWards 		= new Wards();
	$objBaseWard 	= $objWards->fetchWardsById( $_POST['ward_id'] );
	
	$objBaseWard->setRoomNumber( $_POST['room_number'] );
	$objBaseWard->setWardTypeId( $_POST['ward_type'] );
	$objBaseWard->setRate( $_POST['rate'] );
	$objBaseWard->setIsAvaliable( ( true == valStr( $_POST['is_avaliable'] ) ) ? $_POST['is_avaliable'] : 1 );
	$objBaseWard->setMoveOutDate( ( true == valStr( $_POST['move_out_date'] ) ) ? $_POST['move_out_date'] : 'NULL' );
	$objBaseWard->setReservationId( ( true == valStr( $_POST['reservation_id'] ) ) ? $_POST['reservation_id'] : 'NULL' );
	$objBaseWard->setReportingDoctorId( ( true == valStr( $_POST['reporting_doctor_id'] ) ) ? $_POST['reporting_doctor_id'] : 'NULL' );
	$objBaseWard->setPatientId( ( true == valStr( $_POST['patient_id'] ) ) ? $_POST['patient_id'] : 'NULL' );
	$objBaseWard->setDepartmentId( $_POST['department_id'] );
	$objBaseWard->setFacilities( ( true == valStr( $_POST['facilities'] ) ) ? $_POST['facilities'] : 'NULL' );
	$objBaseWard->setCreatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseWard->setUpdatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseWard->setUpdatedOn( 'now()' );
	
	if( 1 == $objBaseWard->update() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_wards&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
}

?>